package com.example.lj.uav.adapter;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.lj.uav.R;
import com.example.lj.uav.bean.CameraItem;
import com.example.lj.uav.holder.CameraHolder;

import java.util.List;

public class CameraAdapter extends RecyclerView.Adapter<CameraHolder> {
    private List<CameraItem> items;
    private Handler handler;
    private Context context;

    public CameraAdapter(Context context,List<CameraItem> items, Handler handler) {
        this.context = context;
        this.items = items;
        this.handler = handler;
    }

    @Override
    public CameraHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_camera,null);
        return new CameraHolder(view);
    }

    @Override
    public void onBindViewHolder(final CameraHolder holder, final int position) {
        holder.tv_camera_name.setText(items.get(position).getName());
        holder.iv_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Message msg = handler.obtainMessage();
                msg.what = 0;
                msg.arg1 = position;
                handler.sendMessage(msg);
            }
        });
    }

    @Override
    public int getItemCount() {
        return items.size();
    }
}
